package com.woniuxy.woniubookmanager.mapper;

import com.woniuxy.woniubookmanager.entity.UrlPermission;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.woniubookmanager.vo.PermissionMenu;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 菜单和接口权限定义 Mapper 接口
 * </p>
 *
 * @author wugd
 * @since 2022-11-29 04:03:13
 */
@Mapper
public interface UrlPermissionMapper extends BaseMapper<UrlPermission> {

    List<PermissionMenu> selectAllMenu();

    @Select("select id ,name from t_url_permission where parent_id = -1")
    List<PermissionMenu> selectParentMenu();

    @Select("select * from t_url_permission where parent_id = #{id}")
    List<UrlPermission> selectPermissionByParentId(Long id);

    @Delete("delete from t_role_url_permission where url_permission_id = #{id}")
    void deletePermisisonAndRoleOfRelation(Long id);
    
    @Select("select up.id  from t_url_permission up INNER JOIN t_role_url_permission rup on up.id = rup.url_permission_id  where rup.role_id = #{id}")
    Long[] selectPermissionIdByRoleId(Long id);

    List<PermissionMenu> selectPermissionMenuByUsername(String name);
}
